/*
 * Copyright:  2018 smarabbit studio.
 *
 *  Licensed under the Confluent Community License; you may not use this file
 *  except in compliance with the License.  You may obtain a copy of the License at
 *
 *  http://www.confluent.io/confluent-community-license
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 *  WARRANTIES OF ANY KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations under the License.
 *
 *  @作   者： 黄开晖 (117227773@qq.com)
 *  @日   期:  2021年5月29日
 */
package com.massyframework.beanskin.runtime;

import java.util.function.Function;

import com.massyframework.beanskin.ModuleExistsException;
import com.massyframework.beanskin.ModuleIdentifier;
import com.massyframework.beanskin.ModuleNotFoundException;
import com.massyframework.beanskin.assembly.Assembly;
import com.massyframework.beanskin.fragment.Fragment;
import com.massyframework.beanskin.fragment.FragmentBuilder;
import com.massyframework.beanskin.library.Library;
import com.massyframework.beanskin.license.License;
import com.massyframework.beanskin.plugin.Plugin;
import com.massyframework.beanskin.plugin.PluginActivator;

/**
 * 模块注册器
 * @author huangkh
 *
 */
public interface ModuleRegistry {
	
	/**
	 * 绑定模块许可
	 * @param license {@link License}
	 */
	void bindLicense(License license);
	
	/**
	 * 重新加载片段
	 * @param identifier {@link ModuleIdentifier},片段的模块标识符
	 * @param action {@link Function},新片段的加载动作
	 * @throws ModuleNotFoundException 如果未找到对应标识符的片段，则抛出例外
	 */
	void reloadFragment(ModuleIdentifier identifier, Function<FragmentBuilder, Fragment> action) throws ModuleNotFoundException;
		
	/**
	 * 注册类库
	 * @param <M>
	 * @param library {@link Library},类库
	 * @throws ModuleExistsException 模块重复注册时，抛出的例外
	 */
	void register(Library library) throws ModuleExistsException;
	
	/**
	 * 注册插件
	 * @param <M>
	 * @param plugin {@link Plugin},插件
	 * @param activator {@link PluginActivator}, 插件激活器
	 * @throws ModuleExistsException 模块重复注册时，抛出的例外
	 */
	void register(Plugin plugin, Function<Plugin, PluginActivator> action) throws ModuleExistsException;
	
	/**
	 * 注册装配件
	 * @param <M>
	 * @param assembly {@link Assembly},装配件
	 * @throws ModuleExistsException 模块重复注册时，抛出的例外
	 */
	void register(Assembly assembly) throws ModuleExistsException;
	
	/**
	 * 注册片段
	 * @param <M>
	 * @param fragment {@link Assembly},装配件
	 * @param installing {@link boolean}, 是否伴随片段的安装
	 * @throws ModuleExistsException 模块重复注册时，抛出的例外
	 */
	void register(Fragment fragment, boolean installing) throws ModuleExistsException;
	
	/**
	 * 取消许可绑定
	 * <p>
	 * 提供许可的模块被卸载，或者{@code license}到期，都会被取消许可绑定
	 * @param license
	 */
	void unbindLicense(License license);
	
	/**
	 * 注销所有插件
	 */
	void unregisterPlugins();
}
